|
|
|
|
|
|
|
LISTING 6.3. THEadjustBalanceMETHOD WITH A RAISED EVENT. |
|
|
|
 |
|
|
|
|
1: Public Function adjustBalance(argObject As Deposit,
argAccountNumber As String) As Boolean
2: Dim LocalObject As Object, returns As Boolean
3:
4: 'If there's more than one account object in memory, a precondition
5: 'is that this object is the correct object. So check account number
6: If argAccountNumber <> AccountNumber Then
7: 'Raise exceptions here
8: Dim sMsg As String
9: sMsg = Wrong account number, Please retry.
10: RaiseEvent OnWrongAccountNumber(sMsg)
11: Set LocalObject = Nothing
12: Exit Function
13: End If
14:
15: 'Delegate to private methods, where only one will be able to
process the message.
16:
17: Set LocalObject = argObject
18:
19: returns = increaseBalance(LocalObject)
20: If returns Then
21: adjustBalance = returns
22: Set LocalObject = Nothing
23: Exit Function
24: End If
25:
26: returns = decreaseBalance(LocalObject)
27: If returns Then
28: adjustBalance = returns
29: Exit Function
30: Set LocalObject = Nothing
31: End If
32: End Function |
|
|
|
|
|
|
|
|
Notice the use of RaiseEvent OnWrongAccountNumber. Raising events is simple. To add an event, make sure that the BasicPersonalChecking class is the current module. Choose Tools | Add Procedure. You'll see the Add Procedure dialog box. Remember this dialog box from earlier? Enter OnWrongAccountNumber for the name of the event; then click the Event option button in the Type frame. Click OK. Visual Basic automatically adds a declaration for the event in the General Declarations of the BasicPersonalChecking class. Now enter the following line of code in the same location, as illustrated in Listing 6.3: |
|
|
|
|
|
|
|
|
Dim sMsg As String
sMsg = Wrong account number, Please retry.
RaiseEvent OnWrongAccountNumber(sMsg) |
|
|
|
|
|